package com.powernode.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.powernode.domain.IndexImg;
import com.powernode.domain.Prod;
import com.powernode.feign.IndexImgToProdFeign;
import com.powernode.service.IndexImgService;
import com.powernode.mapper.IndexImgMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 *
 */
@Service
public class IndexImgServiceImpl extends ServiceImpl<IndexImgMapper, IndexImg>
        implements IndexImgService {

    @Autowired
    private IndexImgMapper indexImgMapper;

    @Autowired
    private IndexImgToProdFeign indexImgToProdFeign;

    @Override
    public Page<IndexImg> indexImgPage(Page<IndexImg> page, IndexImg indexImg) {
        return indexImgMapper.selectPage(page, new LambdaQueryWrapper<IndexImg>()
                .eq(!ObjectUtils.isEmpty(indexImg.getStatus()), IndexImg::getStatus, indexImg.getStatus()));
    }

    @Override
    public IndexImg getIndexImgInfoById(Long id) {
        //查询轮播
        IndexImg indexImg = indexImgMapper.selectById(id);
        //由于轮播可能绑定有商品 在查询商品
        Long prodId = indexImg.getRelation();
        if (!ObjectUtils.isEmpty(prodId)) {
            //说明有商品
            //使用feign调用prod
            Prod prodInfo = indexImgToProdFeign.getProdInfo(prodId);
            indexImg.setPic(prodInfo.getPic());
            indexImg.setProdName(prodInfo.getProdName());
        }
        return indexImg;
    }
}




